package com.feib.soeasy.dao;

import java.util.Calendar;
import java.util.Date;

import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.feib.soeasy.model.Group;
import com.feib.soeasy.model.UploadFile;
import com.feib.soeasy.pagination.PaginatedList;


/**
 * @title (#)UploadFileDaoTester.java<br>
 * @description <br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/14 create by Jimmy Liu<br>
 */
public class UploadFileDaoTester 
{
    private static ApplicationContext context;

    private static UploadFileDao uploadFileDao;
    
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @BeforeClass
    public static void runBeforeClass()
    {
        context = new FileSystemXmlApplicationContext(new String[] {
                        "src/main/webapp/WEB-INF/spring/applicationContext-config.xml"
                        , "src/main/webapp/WEB-INF/spring/applicationContext-dao.xml"
                        , "src/main/webapp/WEB-INF/spring/applicationContext-hibernate.xml"
        });

        uploadFileDao = (UploadFileDao) context.getBean("uploadFileDao");

    }
    
    @Test
    public void queryPaginationByUploadFile()
    {
        UploadFile uploadFile = new UploadFile();
        Group uploadGroup = new Group();
        uploadGroup.setGroupPk(new Long(1));
        uploadFile.setGroup(uploadGroup);
        //uploadFile.setFileName("upload");
        

        Calendar cal = Calendar.getInstance();
        cal.set(2000, 10, 14, 3, 3);
        Date uploadFrom = cal.getTime();
        
        cal = Calendar.getInstance();
        cal.set(2011, 10, 15, 3, 3);
        Date uploadTo = cal.getTime();
        
        logger.info(uploadFrom.toString());
        logger.info(uploadTo.toString());
        
        PaginatedList<UploadFile> paginationConfig = new PaginatedList<UploadFile>();
        
        PaginatedList<UploadFile> queryResult = uploadFileDao.queryPaginationByUploadFile(uploadFile, uploadFrom, uploadTo, paginationConfig);
        
        logger.info(queryResult.toString());
    }
}
